package com.itheima.service;

import com.itheima.dao.IManagerDao;
import com.itheima.domain.Manager;
import com.itheima.factory.Factory;

import java.io.IOException;
import java.util.ArrayList;

public class ImplManagerService implements IManagerService {
    private IManagerDao managerDao = Factory.getManagerDao();

    @Override
    public int manLogin(String id, String password) {
        return managerDao.manLogin(id, password);
    }

    @Override
    public void register(Manager manger) {
        try {
            managerDao.register(manger);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void updateMan(String id, Manager manager) {
        try {
            managerDao.updateMan(id, manager);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public ArrayList<Manager> findAll() {
        return managerDao.findAll();
    }

    @Override
    public Manager findMan(String id) {
        return managerDao.findMan(id);
    }

    @Override
    public boolean isExists(String id) {
        ArrayList<Manager> manlist = managerDao.findAll();
        for (Manager manager : manlist) {
            if (id.equals(manager.getId())){
                return false;
            }
        }
        return true;
    }

    @Override
    public ArrayList<String> lookLogger() {
        try {
            return managerDao.lookLogger();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
